import com.adobe.cairngorm.control.CairngormEventDispatcher;

import mx.events.CloseEvent;
import mx.events.ValidationResultEvent;
import mx.managers.PopUpManager;

import net.optix.ip.events.EditBillingEvent;
import net.optix.ip.model.ModelLocator;
import net.optix.ip.vo.ClientVO;
            
[Bindable]
public var model:ModelLocator	=	ModelLocator.getInstance(); 
  
public function init():void
{
 	model.bSubmit	=	true;
	model.result	=	"";
}
  			
private function titleWindow_close(evt:CloseEvent):void { 
 	model.result	=	"";
 	model.bSubmit	=	true;
	PopUpManager.removePopUp(this); 
}
            
            
public function editBilling():void
{	
   	var result:Boolean	=	true;

	var resultValidate:ValidationResultEvent;
				
	resultBusiness.text	=	"";
	resultBillingAddress.text		=	"";
	resultBillingCity.text	=	"";
	resultBillingState.text	=	"";
	resultBillingCountry.text		=	"";
	resultBillingPostalCode.text	=	"";
	resultTaxID.text		=	"";
				
	model.result			=	"";
				
	resultValidate	=	stringValidator.validate(business.text);
    if(resultValidate.type == ValidationResultEvent.INVALID)
    {
       	result	=	false;
      	resultBusiness.text	=	
       	resultValidate.message;
 	}
            	
 	resultValidate	=	stringValidator.validate(billingAddress.text);
	if(resultValidate.type == ValidationResultEvent.INVALID)
	{
     	result	=	false;
     	resultBillingAddress.text	=	resultValidate.message;
	}
            	
  	resultValidate	=	stringValidator.validate(billingCity.text);
 	if(resultValidate.type == ValidationResultEvent.INVALID)
  	{
       	result	=	false;
    	resultBillingCity.text	=	resultValidate.message;
    }
            	
   	resultValidate	=	stringValidator.validate(billingState.text);
	if(resultValidate.type == ValidationResultEvent.INVALID)
 	{
   		result	=	false;
     	resultBillingState.text	=	
            			resultValidate.message;
  	}
            	
  	resultValidate	=	stringValidator.validate(billingCountry.text);
 	if(resultValidate.type == ValidationResultEvent.INVALID)
 	{
      	result	=	false;
     	resultBillingCountry.text	=	
            			resultValidate.message;
  	}
            	
  	resultValidate	=	postalValidator.validate(billingPostalCode.text);
  	if(resultValidate.type == ValidationResultEvent.INVALID)
 	{
      	result	=	false;
     	resultBillingPostalCode.text	=	
            			resultValidate.message;
  	}
            	
   	resultValidate	=	stringValidator.validate(taxID.text);
   	if(resultValidate.type == ValidationResultEvent.INVALID)
   	{
       	result	=	false;
      	resultTaxID.text	=	
            			resultValidate.message;
 	}
            	
            	
  	model.bSubmit	=	false;
   	model.result	=	"";
            	
            	
            	
  	if(result == true)
 	{
       	var vo:ClientVO 	=	model.client;
            	
      	vo.business			=	business.text;
      	vo.billingAddress	=	billingAddress.text;
      	vo.billingCity		=	billingCity.text;
      	vo.billingState		=	billingState.text;
     	vo.billingCountry	=	billingCountry.text;
      	vo.billingPostalCode=	billingPostalCode.text;
       	vo.taxID			=	taxID.text;
       	vo.description		=	description.text;
            		
            		
        var event:EditBillingEvent	=	new EditBillingEvent(vo);
        CairngormEventDispatcher.getInstance().dispatchEvent( event );
  	}
	else
 	{
    	model.bSubmit	=	true;
	}
}